package com.example.demo.services;

import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.example.demo.dao.FriendsLinkDao;
import com.example.demo.model.FriendsLinkModel;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class FriendsLinkService {

    @Resource
    FriendsLinkDao friendsLinkDao;
    @Resource
    RedisTemplate<String, Object> redisTemplate;

    public List<FriendsLinkModel> getAllFriendsLinkList(String orderBy) {
        List<FriendsLinkModel> friendsLinkModelList = null;
        String friendsLinkCacheKey = "friendsLink";
        Object RedisResult = redisTemplate.opsForValue().get(friendsLinkCacheKey);
        if(RedisResult != null) {
            friendsLinkModelList = (List<FriendsLinkModel>) RedisResult;
        } else {
            friendsLinkModelList = friendsLinkDao.getFriendsLinkAllList(orderBy);
            redisTemplate.opsForValue().set(friendsLinkCacheKey, friendsLinkModelList);
        }

        return friendsLinkModelList;
    }
}
